package com.lingnan.controller;

import com.lingnan.entity.Clazz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * \* Author: RIKU
 * \* Date: 2020/6/7 22:02
 * \* Description: //TODO
 * \* To change this template use File | Settings | File Templates.
 * \
 */
@RestController
@RequestMapping("clazz/consumer")
public class ClazzComsumerController {

    @Autowired
    private RestTemplate restTemplate; //提供一些便利的方法直接访问http请求

    private String uriPrefix = "http://provider-clazz";  //"http://localhost:8001"

    @RequestMapping("insert")
    public ResponseEntity<Boolean> insert(Clazz bean) {
        String uri = uriPrefix + "/clazz/insert";
        return restTemplate.postForEntity(uri, bean, Boolean.class);
    }

    @RequestMapping("queryAll")
    public Object queryAll() {
        String uri = uriPrefix + "/clazz/queryAll";
        return restTemplate.getForObject(uri, List.class);
    }

    @RequestMapping("queryById/{id}")
    public Object queryById(@PathVariable Integer id) {
        String uri = uriPrefix + "/clazz/queryById/" + id;
        return restTemplate.getForObject(uri, Clazz.class);
    }

}
